package com.yao.converter;

import com.yao.dataobject.OrderMaster;
import com.yao.dto.OrderDTO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * User: 姚宏武
 * Date: 2017/11/19
 * Time: 17:30
 * Email：401369870@qq.com
 * Description: 订单对象->订单数据传输对象
 */
public class OrderMaster2OrderDTOConverter {
    /**
     * 订单对象转换为订单数据传输对象
     * @param orderMaster
     * @return
     */
    public static OrderDTO convert(OrderMaster orderMaster){
        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(orderMaster,orderDTO);
        return orderDTO;
    }

    /**
     * 订单对象集合转换为订单数据传输对象集合
     * @param orderMasterList
     * @return
     */
    public static List<OrderDTO> convert(List<OrderMaster> orderMasterList){
        return orderMasterList.stream().map(e->
            convert(e)
        ).collect(Collectors.toList());
    }
}
